package org.spring.springcar;

import lombok.val;
import org.spring.springcar.component.UserComponent;
import org.spring.springcar.configuration.UserConfig;
import org.spring.springcar.controller.UController;
import org.spring.springcar.controller.UserController;
import org.spring.springcar.model.UserInfo;
import org.spring.springcar.repository.UserRepository;
import org.spring.springcar.service.UserService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class SpringCarApplication {

    public static void main(String[] args)  {
        // SpringApplication.run(SpringCarApplication.class, args);

        ApplicationContext context = SpringApplication.run(SpringCarApplication.class,args);

/**
        //TODO Controller注解
//        UserController bean = context.getBean(UserController.class);
//       // bean.setName("zhangsan");
//        bean.hello();
//
//        UserController userController = (UserController)context.getBean("userController");
//        userController.hello();
//
//        UserController userController1 = context.getBean("userController",UserController.class);
//        userController1.hello();
//
//        System.out.println(bean);
//        System.out.println(userController);
//        System.out.println(userController1);

//        UController bean = context.getBean(UController.class);
//        bean.hello();
//
//        UController uController = (UController)context.getBean("UController");
//        uController.hello();


        //TODO Service注解
        UserService bean = context.getBean(UserService.class);
        bean.hello();


        //TODO   Component注解
        UserComponent bean1 = context.getBean(UserComponent.class);
        bean1.hello();

        //TODO Configuration注解
        UserConfig bean2 = context.getBean(UserConfig.class);
        bean2.hello();

        //TODO Repository注解
        UserRepository bean3 = context.getBean(UserRepository.class);
        bean3.hello();



        //TODO Bean方法注解
//        UserInfo bean4 = context.getBean(UserInfo.class);
//        System.out.println(bean4);

        //当Bean下有两个对象时，只能通过以下方法运行
        UserInfo userInfo = (UserInfo) context.getBean("userInfo");
        System.out.println(userInfo);
        UserInfo userInfo2 = (UserInfo) context.getBean("userInfo2");
        System.out.println(userInfo2);


 **/



        UserController bean = context.getBean(UserController.class);
        bean.hello();
    }


}
